//
//  UIs_TableVC.swift
//  APSwift
//
//  Created by AbnerPei on 2021/12/30.
//

import UIKit

class UIs_TableVC: UIViewController {
    
    lazy var tableView: UITableView = {
        let tableV = UITableView(frame: view.bounds, style: .plain)
        tableV.delegate = self
        tableV.dataSource = self
        tableV.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        return tableV
    }()
    
    var cellTitles: [String] = []
    var cellVCNames: [String] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
        view.backgroundColor = .white
        
        configDatas()
        view.addSubview(tableView)
    }
    
    func configDatas() {
        cellTitles = [
            "maxbud订阅上下动画",
            "绘制",
            "UICollectionView拖拽",
            "自定义Label（左右有间距）",
            "渐变色",
            "能量柱",
            "UILabel指定宽时文字自适应大小",
            "Injection简单使用",
            "自定义CollectionViewLayout实现的tag",
            "纯文字cell展开与收起",
            "AttributedString（富文本）",
            "九宫格",
            "UI控件的抗压缩、抗拉伸（拥抱）属性",
            "动画示例s"
        ]
        
        cellVCNames = [
            "UIs_maxbud_Subscription_AnimationVC",
            "UIs_draw_TableVC",
            "UIs_UICollectionViewDragDrop_DemoVC",
            "UIs_ABEdgesLabel_DemoVC",
            "UIs_Gradient_DemoVC",
            "UIs_EPEnergy_DemoVC",
            "UIs_UILabelFitWidth_DemoVC",
            "UIs_Injection_DemoVC",
            "UIs_APTagsView_DemoVC",
            "UIs_CellFold_DemoVC",
            "UIs_AttributedString_TableVC",
            "UIs_Sudoku_TableVC",
            "UIs_Hugging_CompressionResistance_DemoVC",
            "UIs_Animation_BaseTableVC"
        ]
    }
    
}

extension UIs_TableVC: UITableViewDataSource, UITableViewDelegate {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return cellTitles.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        cell.textLabel?.text = cellTitles[indexPath.row]
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 60
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        pushToNext(vcTitles: cellTitles, vcNames: cellVCNames, at: indexPath)
    }
}
